let app = getApp()
Page({
  data: {
    cur: 0,
    titArr: [ "浏览记录", "标签", "跟进记录", "AI分析" ],
    buttonTxt: "浏览记录",
    optionInfo: {
        imgUrl: "",
        name: "",
        from: ""
    },
    userInfo: "",
    requestData: {
        imgUrl: "",
        data: []
    },
    btnClick: "",
    popup: {
        tit: "请输入标签不超过10个字",
        btn: [ "取消", "确认" ],
        flag: !1
    },
    tagInput: {
        tags: ""
    },
    browserData: [],
    followData: [],
    browserNodata: !1,
    followNodata: !1,
    followFirst: !1,
    browserPage: 1,
    followPage: 1,
    nodata: !1,
    refreshing: !1,
    addTags: [],
    AIdata: 0,
    tagData: 0,
    page:1,
    page1:1,
    page2:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  getlabelData:function(e){
      this.cur1()
  },
  onLoad: function (options) {
       this.setData({
        optionInfo:options,
        requestData:options,
        imgUrl:decodeURIComponent(options.imgUrl)
       })
       this.cur0()
       this.cur1()
       this.cur2()
  },
  followupdate:function(){
      this.cur2()
  },
  cur0:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
       data: {
         do:'Customer_visit',
         staff_id:wx.getStorageSync('staff_bind_id'),
         cus_id:that.data.optionInfo.cus_id,
         user_openid:that.data.optionInfo.user_openid,
         page:that.data.page
      },
     success: function(res) {
      if(that.data.page==1)
      {
        that.setData({
          browserData:res.data.info
         })
      }else
      {
        var browserData=that.data.browserData
        browserData=browserData.concat(res.data.info)
        that.setData({
          browserData:browserData
        })
      }
    }
    })
  },
  cur1:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
       data: {
         do:'Customer_getCustomerTags',
         staff_id:wx.getStorageSync('staff_bind_id'),
         cus_id:that.data.optionInfo.cus_id,
         page:that.data.page1
      },
     success: function(res) {
         that.setData({
           tagData:res.data.info
         })
     }
  })
  },
  cur2:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
       data: {
         do:'Customer_followOne',
         staff_id:wx.getStorageSync('staff_bind_id'),
         cus_id:that.data.optionInfo.cus_id,
         page:that.data.page2,
         user_openid:that.data.optionInfo.user_openid
      },
     success: function(res) {
         that.setData({
          followData:res.data.info
         })
     }
  })
  },
  choosetit:function(e){
    var index=e.currentTarget.dataset.index
    switch(index){
      case 0:
        this.cur0()
        break;
      case 1:
          this.cur1()
          break;
      case 2:
            this.cur2()
            break;
      default:
          this.cur0()
          break;
    }
    this.setData({
      cur:index
    })
  },
  getPopupData:function(e){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
           data: {
             do:'Customer_addtag',
             staff_id:wx.getStorageSync('staff_bind_id'),
             cus_id:that.data.optionInfo.cus_id,
             tags:e.detail,
             tag:''
          },
         success: function(res) {
          wx.showToast({
            title: '添加成功，请至标签页查看',
            icon: 'none',
            duration: 1500
          })
         }
    }) 
  },
  addlabel:function(e){
    var  popup={
      tit: "请输入标签不超过10个字",
      btn: [ "取消", "确认" ],
      flag: !0,
      x: !1
   }
   this.setData({
       popup:popup
   })
  },
  sendmsg:function(e){
    var t=this.data.optionInfo
    console.log(t)
    wx.navigateTo({
      url: "/business-service/pages/staff_customer/sendmsg?id=" + t.user_id + "&cus_id=" + t.cus_id + "&imgUrl=" + encodeURIComponent(t.imgUrl) + "&name=" + t.name + "&md5=" + t.md5 + "&from=" + t.from + "&user_openid=" + t.user_openid + "&is_intention=" + t.is_intention
    })
  },
  phone:function(){
    var phoneNumber=this.data.optionInfo.phone
    wx.showModal({
      title: '是否要拨打这个电话？',
      content:phoneNumber,
      showCancel: true, 
      cancelText:"取消",
      confirmText:"确定",
      confirmColor: '#3a82f8',
      success: function (res) {
        if (res.cancel) {
        } else{
          wx.makePhoneCall({
            phoneNumber:phoneNumber,
            success:function(){
              wx.request({
                url: app.globalData.siteroot,
                data: {
                  do:'Video_updVideoTimes',
                  id:id,
                  staff_id:wx.getStorageSync('staff_bind_id'),
                  times_type:4,
                  user_id:wx.getStorageSync('user_id')
                },
                success: function(res) {
                  that.setData({
                    videoList:newlist
                 })
                }
              })
             
            },
            fail:function(){
              console.log('拨打失败')
            }
          })
        }
      }})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      if(this.data.cur==0){
        var that=this
        this.setData({
          page:parseInt(that.data.page)+1
       })
          this.cur0()
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})